<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class IndexController extends CommonController{

	//构造函数
	public function __init()
	{
		
	}
	
    //动作
    public function index(){
$catedata = Db::table("360mall_category")->get();
$catedata = 	Data::channelLevel($catedata, $pid = 0, $html = "&nbsp;", $fieldPri = 'cate_id', $fieldPid = 'cate_pid', $level = 1) ;
$data = Db::table("360mall_category")->where("cate_pid",0)->get();
	
	  foreach ($data as $k => $v) {
	  	$cids = array();
	    //找子类分类
	    $cids = $this->getSon(Db::table("360mall_category")->get(), $v['cate_id']);
		
		$cids[] = $v['cate_id'];
		$data[$k]['goods'] = Db::table("360mall_goods")->where("g_cid  in (".implode(",", $cids).")")->orderBy("g_time","desc")->limit(8)->get();
//		p($v['cate_id']);
	  } 
//p($data);

	   View::with("data",$data);
	   View::with("catedata",$catedata);
       View::make();
    }
	//获得子类
	 public function getSon($data,$cate_id){
	  	//静态变量为了防止结果不被覆盖
		 static $temp = array();
		 foreach ($data as $key => $v) {
		 	//条件成立的时候，当前这一条就是$cate_id这一条的子集
		 	if($cate_id==$v['cate_pid']){
		 		$temp[] = $v['cate_id'];
				//递归找子集
				$this->getSon($data,$v['cate_id']);
			}
		}
		return $temp;
	  }
	
	
	

}
